package io.renren.dao;

import io.renren.common.dao.BaseDao;
import io.renren.entity.AutorepairmEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * ${comments}
 *
 * @author Sen 524227263@qq.com
 * @since 1.0.0 2024-05-28
 */
@Mapper
public interface AutorepairmDao extends BaseDao<AutorepairmEntity> {

    @Select("select '维修' as type,SYS_Created from AutoRepairM where Auto_FK =#{autoOID}  " +
            "union All select '美容' as type,SYS_Created from AutoDecorateM where Auto_FK =#{autoOID}  " +
            "union All select '洗车' as type,SYS_Created from AutoWashM where Auto_FK =#{autoOID}  " +
            "union All select '救援' as type,SYS_Created from AutoRescueM where Auto_FK =#{autoOID} " +
            "union All select '保险' as type,SYS_Created from AgencyInsuranceRegM where Auto_FK =#{autoOID} " +
            "union All select 'VIP' as type,SYS_Created from JoinMemberM where Auto_FK =#{autoOID}  " +
            "union All select '车务' as type,SYS_Created from AutoServiceM where Auto_FK =#{autoOID} " +
            "order by SYS_Created desc ")
    List<Map<String, Object>> selectListExSql(@Param("autoOID") String autoOID);

    @Select("select * from AutoRepairItemsD LEFT OUTER JOIN ProjectM ON AutoRepairItemsD.ProjectM_FK = ProjectM .ProjectMOID where RepairProjectKinds ='JC' and AutoRepairM_FK=#{businessKey}")
    List<Map<String, Object>> getAutoRepairItems(@Param("businessKey") String businessKey);

    @Select("SELECT COALESCE(max(QualifiedTime),'') as QualifiedTime from AutoRepairItemsD WHERE QualifiedTime is not null and RepairProjectKinds != 'JC'  and  AutoRepairM_FK =#{businessKey}")
    List<String> getQualifiedTimeList(@Param("businessKey") String businessKey);

    @Select("select AutoWashM.SYS_Created from AutoWashM left join BusinessM on AutoWashM.AutoWashMOID=BusinessM.SettlementM_FK where BusinessM.BusinessBillOID=#{businessKey}")
    List<Map<String, Object>> getwashDateMap(@Param("businessKey") String businessKey);

    @Select("select SettlementM.SYS_Created from SettlementM left join BusinessM on SettlementM.SettlementMOID=BusinessM.SettlementM_FK where BusinessM.SourceBillOID=#{businessKey}")
    List<Map<String, Object>> getjiesuanMap(@Param("businessKey") String businessKey);

    @Select("select distinct UCML_CONTACT.PersonName from AutoRepairDispatchD  " +
            "left join UCML_CONTACT on UCML_CONTACT.UCML_CONTACTOID=AutoRepairDispatchD.UCML_CONTACT_FK  " +
            "where AutoRepairDispatchD.DispatchType='1' and AutoRepairDispatchD.SourceBillOID=#{autoRepairMoId}")
    List<Map<String, Object>> getTechnicianInfo(@Param("autoRepairMoId") String autoRepairMoId);

    @Select("select a.BusinessPrice,a.BusinessAmount,b.Name as goodsName,a.BusinessQuantity,a.Amount,a.Price,b.Units_FK  from Autorepairpickingd a left join  GoodsM b ON a.GoodsM_FK = b.GoodsMOID " +
            "where a.AutoRepairM_FK =#{autoRepairMoId} ")
    List<Map<String, Object>> getgoodsList(@Param("autoRepairMoId") String autoRepairMoId);

    @Select("select a.RepairState,a.QualifiedResult,b.Name, b.Name as projectName ,a.Amount,a.BusinessAmount from Autorepairitemsd a " +
            "left join ProjectM b ON a.ProjectM_FK = b.ProjectMOID " +
            "where AutoRepairM_FK=#{autoRepairMoId}")
    List<Map<String, Object>> getProjuectList(@Param("autoRepairMoId") String autoRepairMoId);

    @Select("select b.Name,b.Name as projectName,a.Amount,a.BusinessAmount from Autorepairitemsd a left join  ProjectM b On a.ProjectM_FK = b.ProjectMOID " +
            "where AutoRepairM_FK=#{autoRepairMoId}")
    List<Map<String, Object>> getProjuectList2(@Param("autoRepairMoId")String autoRepairMoId);
}